//
//  ZPPictureDetailVC.m
//  ZhenPin
//
//  Created by fei on 14-8-15.
//  Copyright (c) 2014年 zhenpin. All rights reserved.
//

#import "ZPPictureDetailVC.h"
#import "MBProgressHUD.h"
@interface ZPPictureDetailVC ()
{
    MBProgressHUD *webHud;
}
@end

@implementation ZPPictureDetailVC

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    NSString *homePath = [NSHomeDirectory() stringByAppendingPathComponent:@"/Documents/ServerConfig.plist"];
    NSMutableDictionary *dataDic = [[NSDictionary dictionaryWithContentsOfFile:homePath] mutableCopy];
    NSMutableString *urlString = [NSMutableString stringWithString:dataDic[@"zpProductDraw"]];
    
    [urlString appendFormat:@"%@",_productId];
    [_pictureWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]];
    _pictureWebView.scalesPageToFit = YES;
    webHud = [[MBProgressHUD alloc] initWithView:self.view];
    [webHud setMode:MBProgressHUDModeIndeterminate];
    [webHud show:YES];
    [webHud setHidden:NO];
    [_pictureWebView addSubview:webHud];
    [self setNavBarButtonItem];
}

-(void)setNavBarButtonItem {

    self.title = @"图文详情";
    
    UIButton *homeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    homeBtn.frame = CGRectMake(0, 0, 44, 44);
    homeBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 20, 0, -10);
    [homeBtn setImage:[UIImage imageNamed:@"home_page"] forState:UIControlStateNormal];
    [homeBtn addTarget:self action:@selector(rightButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithCustomView:homeBtn];
    self.navigationItem.rightBarButtonItem = rightBarItem;
    
    [self.navigationController.navigationBar setBackIndicatorImage:
     [UIImage imageNamed:@"return"]];
    [self.navigationController.navigationBar setBackIndicatorTransitionMaskImage:
     [UIImage imageNamed:@"return"]];
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:nil];
}

-(void)leftBarbuttonItemClicked:(UIButton *)button {
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)rightButtonClicked {
    [self.navigationController popToRootViewControllerAnimated:YES];
}
#pragma mark -- UIWebView Delegate
-(void)webViewDidFinishLoad:(UIWebView *)webView {
    webHud.mode = MBProgressHUDModeText;
//    webHud.labelText = @"加载完成...";
    [webHud hide:YES afterDelay:.2];
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    webHud.mode = MBProgressHUDModeText;
    webHud.labelText = @"加载失败，稍后再试";
    [webHud hide:YES afterDelay:1];
}




- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
